package com.oa.controller;

import com.oa.pojo.Duty;
import com.oa.pojo.Menu;
import com.oa.pojo.Result;
import com.oa.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Menu")
@Api(tags = "菜单：在线接口")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @CrossOrigin
    @ApiOperation(value="查询用户登陆菜单",httpMethod = "GET",notes = "返回包含用户类的result类型json格式")
    @GetMapping("/selectBuUserId")
    public Result selectBuUserId(Integer uid){
        System.out.println("执行根据菜单id查询功能");

        List<Menu> menus=menuService.selectByUserId(uid);
        return Result.success(menus);
    }
    @CrossOrigin
    @ApiOperation(value="根据菜单删除(id)",httpMethod = "GET",notes = "返回包含用户类的result类型json格式")
    @GetMapping("/deleteMenu")
    public Result deleteMenu(Integer id){
        System.out.println("执行根据菜单id删除功能");

        int flag= menuService.deleteMenu(id);
        if (flag==1){
            return Result.success();
        }else {
            return Result.error("没有此id的菜单");
        }
    }

    @CrossOrigin
    @ApiOperation(value="菜单信息更改",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/updateMenu")
    public Result updateMenu(@RequestBody Menu menu){
        System.out.println("执行菜单信息更改接口");

        int flag= menuService.updateMenu(menu);
        if (flag==1) {
            return Result.success();
        }else {
            return Result.error("添加新菜单失败，有重复属性");
        }
    }

    @CrossOrigin
    @ApiOperation(value="添加菜单",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/insertMenu")
    public Result insertMenu(@RequestBody Menu menu){
        System.out.println("执行菜单添加功能接口");

        int flag= menuService.insertMenu(menu);

        if (flag==1) {
            return Result.success();
        }else {
            return Result.error("添加新菜单失败，有重复属性");
        }
    }
}
